package com.ysw.run;

import com.sun.org.apache.bcel.internal.ExceptionConst;
import com.ysw.entity.Student;
import com.ysw.mapper.SQLMapper;
import com.ysw.mapper.StuMapper;
import com.ysw.sql.Mysession;
import com.ysw.sql.Mysql;
import com.ysw.sql.MysqlSession;
import com.ysw.sql.MysqlUnit;
import org.junit.jupiter.api.Test;

/**
 * 这是一个测试类
 */
public class rUN {
    @Test
    public void  insertUser() throws Exception {
        SQLMapper mapper = MysqlSession.getMapper(SQLMapper.class);
        int insertUser = mapper.insertUser(18, "tom");
        System.out.println(insertUser);
    }
    @Test
    public void  selectUser() throws Exception {
        SQLMapper mapper = MysqlSession.getMapper(SQLMapper.class);
        Student stu = mapper.selectUser("tom");
        //有点小问题，这边英文可以查出来，中文如杨式炜会报错
        System.out.println("查询结果:   " + stu.toString());
    }

    @Test
    public void  deleteUserByUserName() throws Exception {
        SQLMapper mapper = MysqlSession.getMapper(SQLMapper.class);
        mapper.deleteUser(5);
    }


    @Test
    public void  updateUser() throws Exception {
        SQLMapper mapper = MysqlSession.getMapper(SQLMapper.class);
        mapper.updateUser(20,1);
    }

    public static void main(String[] args) throws IllegalAccessException, InstantiationException {
        Mysql mysql =new Mysql();
        StuMapper mapper=mysql.getMapper(StuMapper.class);
        MysqlUnit mysqlUnit=new MysqlUnit();
        SQLMapper mapper0 = MysqlSession.getMapper(SQLMapper.class);
       // xml查询
//        try {
//            System.out.println("~~~~~~~~~~~~~~~准备执行查询操作");
//            Student student=mapper.selectById(5);
//            if(student.getId()==0){
//                System.out.println("~~~~~~~~~~~~~~~查询成功，但该表里没有这个数据~~~~~~~~~~~~~~~~~~~~~");
//            }else{
//            System.out.println("~~~~~~~~~~~~~~~xml查询成功，内容如下");
//            System.out.println(student);
//        }
//        } catch (Exception e) {
//            System.out.println("xml查询出错");
//            e.printStackTrace();
//        }
        //xml插入
//        try{
//            Student student=new Student();
//            student.setId(7);
//            student.setSex("男");
//            student.setStuname("yyy");
//            student.setStunumber(110);
//            student.setAge(11);
//            mapper.insert(student);
//            System.out.println("xml插入成功");
//        }catch (Exception e){
//            System.out.println("xml插入失败");
//        }
//
//        //xml修改
//        try{
//            Student student=new Student();
//            student.setId(3);
//            student.setStuname("要修改的人");
//            student.setSex("男");
//            student.setStuname("yyy000");
//            student.setStunumber(110110);
//            student.setAge(1221);
//            mapper.updateById(student);
//            System.out.println("xml修改成功");
//        }catch (Exception e){
//            System.out.println("xml修改失败");
//        }
        //xml删除
//        try{
//            mapper.deleteById(2);
//            System.out.println("xml删除成功");
//        }catch (Exception e){
//            System.out.println("xml删除+失败");
//        }
    }
}
